def pr(a):
    x = int(a)
    flag = True
    for i in range(2,x):
        if x % i == 0:
            flag = False
    if x == 0 or x == 1: flag = False
    return flag

s = input()
a = []
for i in s:
    if pr(i) == True:
        a.append(int(i))
if pr(s[:2]) == True:
    a.append(int(s[:2]))
if pr(s[1:3]) == True:
    a.append(int(s[1:3]))
if pr(s[2:]) == True:
    a.append(int(s[2:]))
if pr(s[:3]) == True:
    a.append(int(s[:3]))
if pr(s[1:]) == True:
    a.append(int(s[1:]))
if pr(s) == True:
    a.append(int(s))
if len(a) == 0 or len(s) != 4:
    print(0)
else:
    print(max(a))



